#include "database/MappingStorage.h"
#include "database/DatabaseManager.h"
#include <QJsonObject>

MappingStorage::MappingStorage(QObject *parent) : QObject(parent) {}
MappingStorage::~MappingStorage() {}

bool MappingStorage::saveMappings(const QString &versionId, const QMap<QString, QString> &mappings)
{
    QJsonObject jsonMappings;
    for (auto it = mappings.begin(); it != mappings.end(); ++it) {
        jsonMappings[it.key()] = it.value();
    }
    return DatabaseManager::instance().saveMappings(versionId, jsonMappings);
}

QMap<QString, QString> MappingStorage::loadMappings(const QString &versionId)
{
    QMap<QString, QString> mappings;
    QJsonObject jsonMappings = DatabaseManager::instance().getMappings(versionId);
    for (auto it = jsonMappings.begin(); it != jsonMappings.end(); ++it) {
        mappings[it.key()] = it.value().toString();
    }
    return mappings;
}